<?php
$form_name="form_from_table"."_";
$createFormTemplates = dirname(__FILE__).DIRECTORY_SEPARATOR.'createFormTemplates';
?>
<form  method="post" name="<?php echo $form_name?>" action="">
<input type="hidden" name="<?php echo $form_name?>posted" value="1"/>
	<table>
	<tbody>
<tr>
	<td width="250">Имя таблицы</td>
	<td>
		<select name="table_name" id="table_name" value="<?php echo Form::value( $form_name, "table_name");?>" >
			<option></option>
			<?php
				$tables = DB::showTables();
				echo Form::createSelectOptions( array_combine( $tables, $tables ), Form::value( $form_name, "table_name") ); 
			?>
		</select>
		<div class="error-msg" id="table_name_error"><?php echo Form::error( $form_name, "table_name" )?></div>
	</td>
</tr>
<tr>
	<td width="250">Шаблон формы</td>
	<td>
		<select name="form_templates" id="form_templates" value="<?php echo Form::value( $form_name, "form_templates");?>" >
			<option></option>
			<?php
				$files_array = files_array( $createFormTemplates, true, true);
				echo Form::createSelectOptions( reset($files_array), Form::value( $form_name, "form_templates") ); 
			?>
		</select>
		<div class="error-msg" id="table_name_error"><?php echo Form::error( $form_name, "form_templates" )?></div>
	</td>
</tr>

	</tbody>	
	</table>
	<input type="submit" name="submit" value="Create..."/>
</form>
<?php
if( isset($_REQUEST[$form_name."posted"]) ){
	if( file_exists( $_REQUEST['form_templates'] ) )
		echo Form::createFormFromTable( $_REQUEST['table_name'], $_REQUEST['form_templates'] );
		
	foreach( $_REQUEST as $name=>$value ) 
		if( strstr( $form_name, $name )==0 ) Form::value( $form_name.$name, $value );	
}
?>
<?php
	myPrint( $files_array, '$files_array' );
	myPrint( Form::$values, 'Form::$values' );
?>